package com.zlx.guguanjia.mapper.provider;

import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author 周罗校
 * @Description
 * @ClassName SysUserSqlProvider
 * @date 2020.11.03 17:30:38
 * 该版权归周罗校所有，最终解释权以官方为准
 */
public class SysUserSqlProvider {
    public String selectPage(Map<String,Object> map){
        return new SQL(){{
            SELECT("of.`name` company_name,ro.`name` role_name,u.* ");
            FROM("sys_user u");
            LEFT_OUTER_JOIN("sys_office of ON u.company_id = of.id " +
                    "LEFT JOIN sys_user_role uro ON u.id = uro.user_id " +
                    "LEFT JOIN sys_role ro ON uro.role_id = ro.id ");
            WHERE("u.del_flag = '0'");
            if (map.containsKey("userNo")&&!StringUtils.isEmpty(map.get("userNo"))){
                WHERE("u.no = #{userNo}");
            }
            if (map.containsKey("oid")&&!StringUtils.isEmpty(map.get("oid"))){
                WHERE("of.id = #{oid}");
            }
            if (map.containsKey("rid")&&!StringUtils.isEmpty(map.get("rid"))){
                WHERE("uro.role_id = #{rid}");
            }
            if (map.containsKey("name")&&!StringUtils.isEmpty(map.get("name"))){
                WHERE("u.`name` LIKE CONCAT('%',#{name},'%')");
            }
        }
        }.toString();
    }
}
